home *** CD-ROM | disk | FTP | other *** search
- Path: mudskipper.cac.psu.edu!user
- From: fcusack@tdx.org (frank.)
- Newsgroups: comp.lang.c++,comp.lang.c,comp.os.msdos.programer,comp.os.ms-windows.programmer.misc
- Subject: Re: fastest code
- Date: Mon, 15 Apr 1996 14:35:17 -0400
- Organization: Soylent Green is People!!
- Message-ID: <fcusack-1504961435170001@mudskipper.cac.psu.edu>
- References: <316112A2.7D37@public.sta.net.cn> <31611AC9.7DE1@wight.hursley.ibm.com> <3162c21a.6084138@204.248.25.97> <31641DE2.31D4@halcyon.com> <31658942.99299605@204.248.25.97> <4kp41m$jhc@news.manawatu.gen.nz>
- NNTP-Posting-Host: mudskipper.cac.psu.edu
-
- In article <4kp41m$jhc@news.manawatu.gen.nz>, gthomas@manawatu.gen.nz wrote:
-
- > srwillrd@novia.net (William E. Kempf) wrote:
- >
- > >As an example: if the C code looked like this...
- >
- > >while (condition)
- > >{
- > > a = 10;
- > > // other code that does not change a
- > >}
- >
- > >a good optimizing compiler would move the a = 10 statement before the
- > >loop in the final machine code.
- >
- > How about this sequence:
- >
- > b = 6;
- > a = 5;
- > while (b < 4)
- > {
- > a = 10;
- > // other code that does not affect q
- ^^^
-
- What is q?
-
- > }
- >
- > Your "optimizing" compiler would come out of that one with a == 10,
- > when it should be a == 5
- >
-
- No, it should be a == 10. The 'a' inside the loop is the same as the one
- outside the loop because you did not declare a new variable. IF, on the
- other hand, you had written:
-
- b = 6;
- a = 5;
- while (b < 4) {
- int a = 10;
- // code that does not affect either a
- }
-
- the "optimizing" compiler will still move a outside the loop, but when the
- loop is exited, a will again be 5. ie the compiler will treat it as if the
- inner a were a totally different variable, as it is.
-
- ~Frank
- - Through the modem, past the router, over the firewall.. nothing but Net -
- - PGP ID: 1C0F6685 | NCB#56 | Visit me --> http://www.tdx.org/~fcusack/ -
-